Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Aug 4, 2025

Summary by CodeRabbit

  • New Features

    • Improved handling of default values during batch creation, ensuring missing fields are automatically filled with their default values when supported by the database dialect.
  • Bug Fixes

    • Adjusted method signatures to require arguments for certain database operations, improving consistency and reliability.
  • Tests

    • Enhanced test coverage for default value handling, including new scenarios for batch creation and default Boolean fields.
  • Chores

    • Updated version numbers across multiple packages to 3.0.0-alpha.18.

Copilot AI review requested due to automatic review settings August 4, 2025 14:25
@coderabbitai
Copy link

coderabbitai bot commented Aug 4, 2025

Walkthrough

This update primarily increments the version number from 3.0.0-alpha.17 to 3.0.0-alpha.18 across multiple package.json files in the repository. Additionally, it introduces dialect-specific support for insert operations with default values, adjusts TypeScript type signatures, updates test schemas and assertions for default values, and improves handling of default values in batch inserts.

Changes

Cohort / File(s) Change Summary
Version Bump (package.json files)
package.json, packages/cli/package.json, packages/common-helpers/package.json, packages/create-zenstack/package.json, packages/dialects/sql.js/package.json, packages/eslint-config/package.json, packages/ide/vscode/package.json, packages/language/package.json, packages/runtime/package.json, packages/sdk/package.json, packages/tanstack-query/package.json, packages/testtools/package.json, packages/typescript-config/package.json, packages/vitest-config/package.json, packages/zod/package.json, samples/blog/package.json, tests/e2e/package.json
Bumped version number from 3.0.0-alpha.17 to 3.0.0-alpha.18; no other changes.
Dialect Support for Insert with Default
packages/runtime/src/client/crud/dialects/base.ts, packages/runtime/src/client/crud/dialects/postgresql.ts, packages/runtime/src/client/crud/dialects/sqlite.ts
Added abstract and concrete getter supportInsertWithDefault to indicate dialect support for inserting with default values (true for PostgreSQL, false for SQLite).
Contract and Type Adjustments
packages/runtime/src/client/contract.ts
Changed example variable names in comments from client to db. Updated findUnique and findUniqueOrThrow method signatures to require the args parameter.
Batch Insert Default Value Handling
packages/runtime/src/client/crud/operations/base.ts
Added logic to fill missing fields with default values for dialects not supporting DEFAULT in batch inserts. Removed commented-out try-catch block in create method.
Test Schema and Assertion Updates
packages/runtime/test/client-api/default-values.test.ts
Changed model schema to use id (Int) as primary key instead of uuid (String), added a bool field with default false, and updated tests to check default value behavior in single and batch inserts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Poem

A hop, a skip, a version jump,
From alpha.17 to .18—thump!
Dialects now know their default fate,
And batch inserts handle missing state.
Tests get new fields, types align anew,
The codebase grows stronger—
🐇 Cheers from the review crew!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@claude
Copy link

claude bot commented Aug 4, 2025

Claude finished @ymc9's task —— View job


Pull Request Review Complete ✅

I've completed a comprehensive review of this PR which merges dev to main for version 3.0.0-alpha.18. Here's my detailed analysis:

Review Tasks:

  • Read and analyze key changed files to understand the scope of changes
  • Review package.json version bumps for consistency
  • Analyze runtime contract.ts changes for code quality and potential issues
  • Review CRUD operation changes in base.ts and dialect files
  • Examine test updates for completeness and quality
  • Check for security concerns in the changes
  • Assess performance implications of changes
  • Provide comprehensive review feedback via GitHub comment

📋 Summary

This PR appears to be a routine release preparation, updating version numbers across all packages from 3.0.0-alpha.17 to 3.0.0-alpha.18 and includes several important bug fixes and improvements to the runtime package.

✅ Positive Findings

Version Consistency

  • All 23 package.json files have been consistently updated to version 3.0.0-alpha.18
  • Version bumps follow the expected alpha versioning pattern
  • No version inconsistencies detected

Code Quality

  • Well-documented API: The contract.ts file maintains excellent JSDoc documentation with comprehensive examples
  • Proper error handling: Query errors include SQL and parameters for debugging when debug mode is enabled
  • Type safety: Strong TypeScript typing throughout with proper generic constraints
  • Clean architecture: Clear separation between dialects, operations, and client contract

Bug Fixes & Improvements

  • SQLite createMany fix: New supportInsertWithDefault property addresses column mismatching issues in SQLite
  • Default value handling: Improved logic for handling records with different field sets in createMany operations
  • ID generator updates: Enhanced support for cuid2, uuid v7, and parameterized nanoid generation

Security

  • No security concerns identified: All changes appear to be internal improvements
  • Proper SQL injection protection: Uses parameterized queries and Kysely's expression builder
  • Input validation: Maintains proper validation and normalization patterns

🔍 Detailed Analysis

Runtime Contract Changes (contract.ts)

  • Lines 169-203: Enhanced procedure type mapping with better generic type handling
  • Documentation quality: Extensive inline examples showing proper usage patterns
  • API consistency: Maintains backward compatibility while adding new features

CRUD Operations (base.ts)

  • Lines 873-906: New logic for handling SQLite's limitations with DEFAULT values in insertMany
  • Performance consideration: Only processes field normalization when necessary
  • Error handling: Appropriate fallbacks for unsupported dialect features

Test Coverage

  • Lines 95-107: Added comprehensive tests for mixed field scenarios in createMany
  • Generator validation: Tests verify proper UUID, CUID, ULID, and nanoid generation
  • Edge case coverage: Tests handle both explicit values and default value scenarios

Performance Implications

  • Minimal overhead: New logic only activates when needed (SQLite + mixed fields)
  • Optimized queries: Maintains efficient query patterns
  • Memory conscious: Proper handling of large datasets in createMany operations

🎯 Recommendations

  1. Merge Approval: This PR is ready for merge with no blocking issues identified
  2. Testing: The included test coverage appears adequate for the changes made
  3. Documentation: Consider updating changelog to highlight the SQLite createMany fix
  4. Future consideration: The TODO comment on line 910-911 about polymorphic model support should be tracked

🏷️ Change Classification

  • Type: Bug fixes and version bump
  • Risk Level: Low (routine maintenance release)
  • Breaking Changes: None identified
  • Database Compatibility: Improves SQLite support without affecting other providers

This is a solid maintenance release that addresses specific SQLite issues while maintaining code quality and backwards compatibility.


Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR merges the dev branch to main, primarily consisting of a version bump from 3.0.0-alpha.17 to 3.0.0-alpha.18 across all packages, along with improvements to database dialect handling for default values and documentation updates.

  • Version bump across all packages from 3.0.0-alpha.17 to 3.0.0-alpha.18
  • Added dialect-specific support for INSERT with DEFAULT values, particularly for SQLite compatibility
  • Updated documentation examples to use consistent db variable naming instead of client

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
package.json (root) Version bump to 3.0.0-alpha.18
packages/*/package.json Version updates across all package manifests
packages/runtime/src/client/crud/dialects/base.ts Added abstract supportInsertWithDefault property
packages/runtime/src/client/crud/dialects/sqlite.ts Implemented SQLite-specific INSERT DEFAULT handling
packages/runtime/src/client/crud/dialects/postgresql.ts Added PostgreSQL INSERT DEFAULT support
packages/runtime/src/client/crud/operations/base.ts Enhanced createMany operation to handle default values for non-supporting dialects
packages/runtime/src/client/contract.ts Updated documentation examples from 'client' to 'db' variable naming
packages/runtime/test/client-api/default-values.test.ts Updated test schema and added comprehensive default value testing

@ymc9 ymc9 changed the title merge dev to main merge dev to main (v3.0.0-alpha.18) Aug 4, 2025
@ymc9 ymc9 added this pull request to the merge queue Aug 4, 2025
Merged via the queue into main with commit 4e359fc Aug 4, 2025
6 of 7 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/dialects/sql.js/package.json (1)

3-3: Same check as above

This is the identical version bump; please run the verification script from the other comment to ensure full consistency across the workspace.

🧹 Nitpick comments (3)
packages/runtime/src/client/crud/dialects/base.ts (1)

970-974: Rename getter to match existing “supports” naming convention*

Existing capability flags (supportsUpdateWithLimit, supportsDeleteWithLimit, supportsDistinctOn) all use the supports* prefix. For consistency and easier discoverability, rename the new flag accordingly and adjust the JSDoc grammar:

-/**
- * Whether the dialect support inserting with `DEFAULT` as field value.
- */
-abstract get supportInsertWithDefault(): boolean;
+/**
+ * Whether the dialect supports inserting with `DEFAULT` as a field value.
+ */
+abstract get supportsInsertWithDefault(): boolean;

Remember to update all usages and overrides in concrete dialects.

packages/runtime/src/client/crud/dialects/sqlite.ts (1)

285-288: Synchronise override name with the base getter

If the base class is renamed to supportsInsertWithDefault (see previous comment), adjust the override accordingly:

-override get supportInsertWithDefault() {
+override get supportsInsertWithDefault() {
     return false;
}

No behavioural change—just a naming alignment.

packages/runtime/src/client/crud/dialects/postgresql.ts (1)

345-348: Keep naming consistent with base after refactor

Echoing the earlier suggestion, update the override if the base getter is renamed:

-override get supportInsertWithDefault() {
+override get supportsInsertWithDefault() {
     return true;
}

This preserves the intended semantics while maintaining a coherent API surface.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c76ae24 and ceaaaf8.

📒 Files selected for processing (23)
  • package.json (1 hunks)
  • packages/cli/package.json (1 hunks)
  • packages/common-helpers/package.json (1 hunks)
  • packages/create-zenstack/package.json (1 hunks)
  • packages/dialects/sql.js/package.json (1 hunks)
  • packages/eslint-config/package.json (1 hunks)
  • packages/ide/vscode/package.json (1 hunks)
  • packages/language/package.json (1 hunks)
  • packages/runtime/package.json (1 hunks)
  • packages/runtime/src/client/contract.ts (28 hunks)
  • packages/runtime/src/client/crud/dialects/base.ts (1 hunks)
  • packages/runtime/src/client/crud/dialects/postgresql.ts (1 hunks)
  • packages/runtime/src/client/crud/dialects/sqlite.ts (1 hunks)
  • packages/runtime/src/client/crud/operations/base.ts (2 hunks)
  • packages/runtime/test/client-api/default-values.test.ts (3 hunks)
  • packages/sdk/package.json (1 hunks)
  • packages/tanstack-query/package.json (1 hunks)
  • packages/testtools/package.json (1 hunks)
  • packages/typescript-config/package.json (1 hunks)
  • packages/vitest-config/package.json (1 hunks)
  • packages/zod/package.json (1 hunks)
  • samples/blog/package.json (1 hunks)
  • tests/e2e/package.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
{packages,samples,tests}/**

📄 CodeRabbit Inference Engine (CLAUDE.md)

Packages are located in packages/, samples/, and tests/

Files:

  • packages/runtime/src/client/crud/dialects/sqlite.ts
  • packages/sdk/package.json
  • packages/runtime/test/client-api/default-values.test.ts
  • packages/ide/vscode/package.json
  • packages/tanstack-query/package.json
  • packages/eslint-config/package.json
  • packages/language/package.json
  • packages/testtools/package.json
  • tests/e2e/package.json
  • packages/cli/package.json
  • packages/runtime/src/client/crud/dialects/base.ts
  • packages/zod/package.json
  • packages/common-helpers/package.json
  • packages/runtime/package.json
  • packages/create-zenstack/package.json
  • packages/dialects/sql.js/package.json
  • samples/blog/package.json
  • packages/vitest-config/package.json
  • packages/runtime/src/client/crud/operations/base.ts
  • packages/runtime/src/client/crud/dialects/postgresql.ts
  • packages/typescript-config/package.json
  • packages/runtime/src/client/contract.ts
tests/e2e/**

📄 CodeRabbit Inference Engine (CLAUDE.md)

E2E tests are in tests/e2e/ directory

Files:

  • tests/e2e/package.json
🧠 Learnings (7)
📚 Learning: `zenstack generate` compiles zmodel to typescript schema (`schema.ts`)...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: `zenstack generate` compiles ZModel to TypeScript schema (`schema.ts`)

Applied to files:

  • packages/sdk/package.json
  • packages/ide/vscode/package.json
  • packages/tanstack-query/package.json
  • packages/language/package.json
  • package.json
  • packages/cli/package.json
  • packages/zod/package.json
  • packages/create-zenstack/package.json
  • packages/vitest-config/package.json
  • packages/typescript-config/package.json
📚 Learning: schema-first approach with zmodel dsl extension of prisma schema language...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Schema-first approach with ZModel DSL extension of Prisma schema language

Applied to files:

  • packages/runtime/test/client-api/default-values.test.ts
  • packages/language/package.json
📚 Learning: e2e tests validate real-world schema compatibility (cal.com, formbricks, trigger.dev)...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: E2E tests validate real-world schema compatibility (cal.com, formbricks, trigger.dev)

Applied to files:

  • packages/runtime/test/client-api/default-values.test.ts
📚 Learning: language-first design: zmodel dsl compiles to typescript, not runtime code generation...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Language-First Design: ZModel DSL compiles to TypeScript, not runtime code generation

Applied to files:

  • packages/language/package.json
📚 Learning: zmodel schema (`schema.zmodel`) defines database structure and policies...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: ZModel schema (`schema.zmodel`) defines database structure and policies

Applied to files:

  • packages/language/package.json
📚 Learning: applies to tests/e2e/** : e2e tests are in `tests/e2e/` directory...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Applies to tests/e2e/** : E2E tests are in `tests/e2e/` directory

Applied to files:

  • tests/e2e/package.json
📚 Learning: kysely-based orm: v3 uses kysely as query builder instead of prisma runtime dependency...
Learnt from: CR
PR: zenstackhq/zenstack-v3#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-04T08:43:33.161Z
Learning: Kysely-Based ORM: V3 uses Kysely as query builder instead of Prisma runtime dependency

Applied to files:

  • packages/dialects/sql.js/package.json
  • packages/runtime/src/client/crud/operations/base.ts
🧬 Code Graph Analysis (2)
packages/runtime/test/client-api/default-values.test.ts (1)
samples/blog/zenstack/schema.ts (1)
  • schema (9-228)
packages/runtime/src/client/crud/operations/base.ts (2)
packages/sdk/src/schema/schema.ts (1)
  • BuiltinType (84-94)
packages/language/src/generated/ast.ts (1)
  • BuiltinType (101-101)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-test (20.x)
  • GitHub Check: claude-review
🔇 Additional comments (26)
packages/runtime/src/client/crud/operations/base.ts (2)

522-528: LGTM! Good cleanup of dead code.

Removing the commented-out try-catch block improves code readability. The error handling appears to be managed by the executeQueryTakeFirst method, making this wrapper redundant.


873-907: LGTM! Well-implemented dialect-specific default value handling.

This enhancement elegantly handles dialects that don't support DEFAULT as insert field values by pre-populating missing fields with their actual default values. The implementation correctly:

  • Collects all fields across the batch to ensure consistency
  • Only fills primitive defaults (excluding objects which likely contain expressions)
  • Uses dialect-specific transformation for the default values

The logic ensures all rows have matching field sets, which is essential for batch inserts in restrictive SQL dialects.

packages/runtime/src/client/contract.ts (4)

62-62: LGTM! Documentation consistency improvement.

The variable name change from client to db in the raw query method examples improves clarity and follows common database client naming conventions.

Also applies to: 72-72, 81-81, 91-91


228-287: LGTM! Consistent documentation improvement.

The variable name changes from client to db in all CRUD operation examples maintain consistency with the raw query method updates and improve code readability.

Also applies to: 353-395, 409-424, 439-446, 461-564, 581-591, 605-617, 631-641, 655-663, 678-686, 701-710, 723-731, 744-766


312-312: findUnique args required — no empty calls found

I searched across all TS/JS files and confirmed every findUnique( invocation includes an args object (no occurrences of empty findUnique()). Since all existing calls supply the required parameters, this breaking change is safe to merge.


322-322: findUniqueOrThrow args requirement verified
A repository-wide search confirms every findUniqueOrThrow call provides the required args object (no invocations without arguments were found). No further updates are needed.

packages/runtime/test/client-api/default-values.test.ts (4)

18-22: LGTM! Schema changes support enhanced default value testing.

The schema restructuring properly:

  • Introduces an Int primary key (id) for cleaner test data
  • Retains uuid field with default generator for testing
  • Adds bool field with default false for simple default value validation
  • Updates idFields and uniqueFields consistently

These changes align well with the broader default value handling improvements mentioned in the AI summary.

Also applies to: 63-67, 69-69, 71-71


79-79: LGTM! Improved test naming.

The test name change from "supports generators" to "supports defaults" more accurately describes the test's purpose and aligns with the file name.


85-85: LGTM! Test data adaptation to new schema.

The explicit id: 1 provision adapts correctly to the new Int primary key schema structure.


95-106: Excellent test coverage for batch default values.

The new createMany tests comprehensively validate default value behavior:

  • Verifies default false is applied when bool field is omitted (id: 2)
  • Confirms explicit true value is preserved when provided (id: 3)
  • Tests both scenarios in a single batch operation

This aligns well with the runtime improvements for default value handling in batch inserts mentioned in the AI summary.

packages/zod/package.json (1)

3-3: Version bump acknowledged – looks good

The package moves to 3.0.0-alpha.18 in sync with the rest of the workspace. No additional changes required.

packages/eslint-config/package.json (1)

3-3: Consistent version increment

@zenstackhq/eslint-config now tracks the monorepo at 3.0.0-alpha.18. All good.

samples/blog/package.json (1)

3-3: Sample app version updated

sample-blog correctly advances to 3.0.0-alpha.18. No further action needed.

packages/tanstack-query/package.json (1)

3-3: Package version synchronized

@zenstackhq/tanstack-query now at 3.0.0-alpha.18. Peer-dependency ranges remain compatible; everything in order.

packages/testtools/package.json (1)

3-3: Version bump verified

@zenstackhq/testtools updated to 3.0.0-alpha.18; change aligns with other workspace packages.

packages/sdk/package.json (1)

3-3: Version bump acknowledged and approved

Package version correctly updated to 3.0.0-alpha.18. No other changes detected.

packages/runtime/package.json (1)

3-3: Runtime package version bump looks correct

The version field now reflects 3.0.0-alpha.18. Change is consistent with other packages.

package.json (1)

3-3: Root package version synchronized successfully

Root package.json updated to 3.0.0-alpha.18. Matches workspace packages.

packages/common-helpers/package.json (1)

3-3: Common-helpers version increment verified

Version set to 3.0.0-alpha.18. No additional modifications found.

packages/typescript-config/package.json (1)

3-3: TypeScript-config version bump confirmed

Change to 3.0.0-alpha.18 is correct and in line with the monorepo versioning.

tests/e2e/package.json (1)

3-3: Version bump is consistent – no issues spotted.

The test package is now aligned with the monorepo’s alpha.18 release. ✔️

packages/cli/package.json (1)

6-6: CLI package version correctly incremented.

Nothing else changed; ensure any release scripts/CI tags are updated to publish 3.0.0-alpha.18 to the registry.

packages/language/package.json (1)

4-4: Language package version bump looks good.

No additional schema or export changes detected.

packages/ide/vscode/package.json (1)

4-4: VSCode extension version updated correctly.

Confirm that the Marketplace pre-release publish step uses this exact version string.

packages/vitest-config/package.json (1)

4-4: Vitest-config package aligned with alpha.18.

No further action required.

packages/create-zenstack/package.json (1)

3-3: Monorepo version bump synchronized

All package.json files now reference 3.0.0-alpha.18; no occurrences of 3.0.0-alpha.17 remain. No further action needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants